home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / WIN / UT_SYSTM / INITYME.ZIP / INITYME.MNU < prev   
Encoding:
MarxMenu script  |  1994-11-17  |  24.9 KB  |  1,088 lines

  1. Comment
  2. ==========================================================
  3.  
  4. Computer Tyme IniTyme * Copyright 1993-94 by Marc Perkel
  5. All Rights Reserved
  6.  
  7. Computer Tyme * 411 North Sherman, Suite 300 * Springfield Mo. 65802
  8. (800) 548-5353 Sales * (417) 866-1222 Voice * (417) 866-1665 Data/Fax
  9.  
  10. IniTyme is a Windows *.INI file manipulator. It is designed to assist the
  11. network administrator who has to maintain INI files for many users.
  12.  
  13. USAGE: INITYME ChangeFile IniFile
  14.  
  15. Example:
  16.   INITYME CHANGE.INI SYSTEM.INI
  17.  
  18. ==========================================================
  19. EndComment
  20.  
  21. ;------ Create Variables
  22.  
  23. var
  24.   Orig
  25.   KOrig
  26.   Changes
  27.   UChanges
  28.   NameIndex
  29.   BlockStartIndex
  30.   BlockEndIndex
  31.   CurrentSection
  32.   ThisSection
  33.   NeedsIndexing
  34.   SectionStart
  35.   SectionEnd
  36.   SubFind
  37.   SubReplace
  38.   SubFindG
  39.   SubReplaceG
  40.   GroupSection
  41.   GroupMode
  42.   Sections
  43.   InsertPos
  44.   Logging
  45.   LogHandle
  46.   LogGroup
  47.   LogFirstLine
  48.   NoBackup
  49.   RestoreMode
  50.   TestMode
  51.   ChangeFileName
  52.   IniFileName
  53.   IniToolMode
  54.   ProgName
  55.   Yak
  56.   Quiet
  57.   GlobalDups
  58.   BackupExtension
  59.   BackupName
  60.   FirstProcessFile
  61.  
  62.  
  63. var
  64.   IfArray
  65.   Stack
  66.   GotoList
  67.   IfLine
  68.   GroupList
  69.   ParenLevel
  70.  
  71. Main
  72.  
  73. ;======================= P R O C E D U R E S ===========================
  74.  
  75.  
  76. Procedure IndexFile
  77. var LastTextLine St
  78.    Loop Orig
  79.       St = CleanIniLine(LoopVal)
  80.       if St StartsWith '['
  81.  
  82.          ;-- Process Header
  83.  
  84.          ThisSection = St
  85.          GroupSection = ThisSection = '[GROUPS]'
  86.          CurrentSection = CurrentSection + 1
  87.  
  88.          AppendArray(NameIndex,St)
  89.          AppendArray(BlockStartIndex,succ(LoopIndex))
  90.          if CurrentSection > 1
  91.             AppendArray(BlockEndIndex,LastTextLine)
  92.          endif
  93.       else
  94.          if St > ''
  95.             LastTextLine = LoopIndex
  96.             KOrig[LoopIndex] = KeyString(St)
  97.          endif
  98.       endif
  99.    EndLoop
  100.    Sections = CurrentSection
  101.    CurrentSection = 0
  102.    if Sections > 0
  103.       AppendArray(BlockEndIndex,LastTextLine)
  104.    endif
  105.    NeedsIndexing = False
  106.    TestFreeMemory
  107. EndProc
  108.  
  109.  
  110. Procedure KeyString (St)
  111. var KeyWord
  112.    KeyWord = LeftOfEqual(St)
  113.    if Hash(KeyWord + ThisSection)
  114.  
  115.       ;- duplicates allowed
  116.  
  117.       Return St
  118.    endif
  119.    GroupMode = False
  120.    if GroupSection
  121.       if St StartsWith 'GROUP'
  122.          GroupMode = True
  123.          KeyWord = 'GROUP=' + FilePart(RightOfEqual(St))
  124.       endif
  125.    endif
  126.    Return KeyWord
  127. EndProc
  128.  
  129.  
  130. ;----- When adding or deleting the BlockStartIndex must be updated
  131.  
  132. Procedure AdjustLineIndex (Line, Adj)
  133.    Loop BlockStartIndex
  134.       if LoopVal > Line
  135.          LoopVal = LoopVal + Adj
  136.       endif
  137.    EndLoop
  138.  
  139.    Loop BlockEndIndex
  140.       if LoopVal >= (Line - Adj)
  141.          LoopVal = LoopVal + Adj
  142.       endif
  143.    EndLoop
  144.  
  145.    SectionStart = BlockStartIndex[CurrentSection]
  146.    SectionEnd   = BlockEndIndex[CurrentSection]
  147.  
  148.    if InsertPos >= Line
  149.       InsertPos = InsertPos + Adj
  150.    endif
  151.  
  152. EndProc
  153.  
  154.  
  155. Procedure LogEvent ($St)
  156.    if not (Logging or Yak) then Return
  157.    if LogGroup <> ThisSection
  158.       if (LogGroup <> '') or LogFirstLine
  159.  
  160.          ;- First line of this log session
  161.  
  162.          if LogFirstLine
  163.  
  164.             FileLog(LogHandle,'')
  165.             FileLog(LogHandle,'======================================================')
  166.             FileLog(LogHandle,'')
  167.             FileLog(LogHandle,'MainFile=' + IniFileName)
  168.             FileLog(LogHandle,'ChangeFile=' + ChangeFileName)
  169.             if NovLoginName > ''
  170.                FileLog(LogHandle,'User=' + NovLoginName)
  171.             endif
  172.             FileLog(LogHandle,'Time: ' + DateString + ' ' + TimeString)
  173.             FileLog(LogHandle,'')
  174.             FileLog(LogHandle,'======================================================')
  175.  
  176.          endif
  177.  
  178.          FileLog(LogHandle,'')
  179.          if Yak then Writeln
  180.          FileLog(LogHandle,ThisSection)
  181.          if Yak then Writeln ThisSection
  182.       endif
  183.       LogFirstLine = False
  184.       LogGroup = ThisSection
  185.    endif
  186.    FileLog(LogHandle,St)
  187.    if Yak then Writeln St
  188. EndProc
  189.  
  190.  
  191. Procedure DelLine (Line)
  192.    if Line = 0 then Return
  193.    LogEvent '  Deleted: ' Orig[Line]
  194.    Delete(Orig,Line,1)
  195.    Delete(KOrig,Line,1)
  196.    AdjustLineIndex(Line,-1)
  197. EndProc
  198.  
  199.  
  200. Procedure InsertLine (St,Line)
  201.    ArrayInsert(Orig,Line,1)
  202.    ArrayInsert(KOrig,Line,1)
  203.  
  204.  
  205.    Orig[Line] = St
  206.    KOrig[Line] = KeyString(CleanINILine(Orig[Line]))
  207. EndProc
  208.  
  209.  
  210. ;----- Change a line, 0 for line number adds line
  211.  
  212. Procedure ChangeOrAddLine (St,Line)
  213. var Original
  214.    if Line = 0
  215.  
  216.       ;- add new line
  217.  
  218.       if CurrentSection > 0
  219.  
  220.          if GroupMode
  221.             St = 'Group' + Str(NextGroup) + '=' + RightOfEqual(St)
  222.          endif
  223.  
  224.          ;- Determine Insert Position
  225.  
  226.          if InsertPos = 0
  227.             Line = BlockEndIndex[CurrentSection] + 1
  228.             InsertLine(St,Line)
  229.             AdjustLineIndex(Line,1)
  230.          else
  231.             Line = InsertPos
  232.             InsertPos = 0
  233.             InsertLine(St,Line)
  234.             AdjustLineIndex(Line,1)
  235.          endif
  236.  
  237.          LogEvent '    Added: ' St
  238.       endif
  239.    else
  240.  
  241.       ;- change line
  242.  
  243.       Original = Orig[Line]
  244.       if InsertPos > 0
  245.  
  246.          ;- move the line
  247.  
  248.          Delete(Orig,Line,1)
  249.          Delete(KOrig,Line,1)
  250.          Line = InsertPos
  251.  
  252.          InsertLine(St,Line)
  253.          InsertPos = 0
  254.       endif
  255.  
  256.       if GroupMode
  257.          St = LeftOfEqual(Orig[Line]) + RightOfEqual(St)
  258.       endif
  259.  
  260.       if St <> Original
  261.          LogEvent '  Changed: ' Original ' to ' St
  262.          Orig[Line] = St
  263.          KOrig[Line] = KeyString(CleanIniLine(Orig[Line]))
  264.       endif
  265.    endif
  266. EndProc
  267.  
  268.  
  269. Procedure SetSectionInfo
  270.    if CurrentSection = 0
  271.       ThisSection = ''
  272.       GroupSection = False
  273.       SectionStart = 0
  274.       SectionEnd = 0
  275.    else
  276.       ThisSection = NameIndex[CurrentSection]
  277.       SectionStart = BlockStartIndex[CurrentSection]
  278.       SectionEnd   = BlockEndIndex[CurrentSection]
  279.       GroupSection = ThisSection = '[GROUPS]'
  280.       HashLevel = 2
  281.       Loop GlobalDups
  282.          Hash(LoopVal + ThisSection) = True
  283.       EndLoop
  284.       HashLevel = 1
  285.    endif
  286. EndProc
  287.  
  288.  
  289. Procedure FindSection (St)
  290.    if NeedsIndexing then IndexFile
  291.    CurrentSection = PosInList(St,NameIndex)
  292.    SetSectionInfo
  293. EndProc
  294.  
  295.  
  296. Procedure AddSection (St)
  297. var Lines Proc
  298.    Proc = CleanIniLine(St)
  299.  
  300.    ;- Add a blank line
  301.  
  302.    AppendArray(Orig,'')
  303.    AppendArray(KOrig,'')
  304.  
  305.    ;- Add CurrentSection header
  306.  
  307.    AppendArray(Orig,St)
  308.    AppendArray(KOrig,Proc)
  309.  
  310.    ;- Update Indexes
  311.  
  312.    Lines = NumberOfElements(Orig)
  313.    AppendArray(NameIndex,Proc)
  314.    AppendArray(BlockStartIndex,Lines + 1)
  315.    AppendArray(BlockEndIndex,Lines + 1)
  316.  
  317.    ;- Make new CurrentSection the current CurrentSection
  318.  
  319.    CurrentSection = NumberOfElements(NameIndex)
  320.    SetSectionInfo
  321.  
  322.    if Logging
  323.       LogGroup = UpperCase(St)
  324.       LogEvent ''
  325.       LogEvent LogGroup ' -*- Section Added'
  326.    endif
  327.  
  328. EndProc
  329.  
  330.  
  331. Procedure DelSection (St)
  332. var S E D
  333.    FindSection(St)
  334.    if CurrentSection = 0 then Return
  335.  
  336.    S = BlockStartIndex[CurrentSection] - 1
  337.    E = BlockEndIndex[CurrentSection]
  338.    D = E - S + 1
  339.  
  340.    delete(Orig,S,D)
  341.    delete(KOrig,S,D)
  342.  
  343.    delete(NameIndex,CurrentSection,1)
  344.    delete(BlockStartIndex,CurrentSection,1)
  345.    delete(BlockEndIndex,CurrentSection,1)
  346.    AdjustLineIndex(S,0 - D)
  347.    CurrentSection = 0
  348.  
  349.    if Logging
  350.       LogGroup = ''
  351.       LogEvent ''
  352.       LogEvent UpperCase(St) ' -*- Section Deleted'
  353.    endif
  354.  
  355. EndProc
  356.  
  357.  
  358. Procedure FindLine (St)
  359. ;   Writeln '=> ' St ' ' KeyString(St)
  360.    Return PosInList(KeyString(St),KOrig,SectionStart,SectionEnd)
  361. EndProc
  362.  
  363.  
  364. ;----- Replaces text in block from the list of substitute text.
  365.  
  366. Procedure ApplySubstBlock (SubF,SubR,S,E)
  367. var P St
  368.    if NumberOfElements(SubF) = 0 then Return
  369.    UpperCaseCompare On
  370.    while S <= E
  371.       Loop SubF
  372.  
  373.          St = Orig[S]
  374.          Substitute(Orig[S],SubF[LoopIndex],SubR[LoopIndex])
  375.          if St <> Orig[S] then ChangeOrAddLine(Orig[S],S)
  376.  
  377.       EndLoop
  378.       S = S + 1
  379.    endwhile
  380.    UpperCaseCompare Off
  381.    dispose(SubFind)
  382.    dispose(SubReplace)
  383. EndProc
  384.  
  385.  
  386. Procedure ApplySubst
  387.    if CurrentSection = 0 then Return
  388.    ApplySubstBlock(SubFind,SubReplace,BlockStartIndex[CurrentSection],BlockEndIndex[CurrentSection])
  389.    ApplySubstBlock(SubFindG,SubReplaceG,BlockStartIndex[CurrentSection],BlockEndIndex[CurrentSection])
  390. EndProc
  391.  
  392.  
  393. Procedure NextGroup
  394. var X S E St Match
  395.    X = 1
  396.    repeat
  397.       S = BlockStartIndex[CurrentSection]
  398.       E = BlockEndIndex[CurrentSection]
  399.       Match = False
  400.       while (S <= E) and not Match
  401.          St = 'GROUP' + Str(X)
  402.          Match = pos(St,CleanIniLine(Orig[S])) > 0
  403.          S = S + 1
  404.       endwhile
  405.       if not Match then Return X
  406.       X = X + 1
  407.    until False
  408. EndProc
  409.  
  410.  
  411. Procedure RemoveExtraBlankLines
  412. var Tmp
  413.    Trim(Orig)
  414.    Tmp = Orig
  415.    dispose Orig
  416.    Loop Tmp
  417.       if LoopVal > ''
  418.          TrimTrail(LoopVal)
  419.          AppendArray(Orig,LoopVal)
  420.       endif
  421.    EndLoop
  422.    Tmp = Orig
  423.    dispose Orig
  424.    Loop Tmp
  425.       if LoopIndex > 1
  426.          if LoopVal StartsWith '['
  427.             AppendArray(Orig,'')
  428.          endif
  429.       endif
  430.       AppendArray(Orig,LoopVal)
  431.    EndLoop
  432. EndProc
  433.  
  434.  
  435. Procedure AddItem (Line)
  436. var St List New UNew NewLine Next UNext
  437.    St = CleanIniLine(Orig[Line])
  438.    New = RightOfEqual(Changes[LoopIndex])
  439.    UNew = RightOfEqual(UChanges[LoopIndex])
  440.    St = RightOfEqual(St)
  441.    NewLine = Orig[Line]
  442.    while St > ''
  443.       AppendArray(List,NextWord(St))
  444.    endwhile
  445.    while UNew > ''
  446.       Next = NextWord(New);
  447.       UNext = NextWord(UNew);
  448.       if PosInList(UNext,List) = 0
  449.          NewLine = NewLine + ' ' + Next
  450.       endif
  451.    endwhile
  452.    TrimTrail(NewLine)
  453.  
  454.    ;- delete double spaces
  455.  
  456.    while pos('  ',NewLine) > 0
  457.       Delete(NewLine,pos('  ',NewLine),1)
  458.    endwhile
  459.  
  460.    ;- delete space after =
  461.  
  462.    if pos('= ',NewLine) > 0
  463.       Delete(NewLine,pos('= ',NewLine)+1,1)
  464.    endif
  465.  
  466.    ChangeOrAddLine(NewLine,Line)
  467. EndProc
  468.  
  469.  
  470. Procedure DelItem (Line)
  471. var St List New UNew NewLine Next UNext P
  472.    St = CleanIniLine(Orig[Line])
  473.    UNew = RightOfEqual(UChanges[LoopIndex])
  474.    St = St + ' '
  475.    NewLine = Orig[Line]
  476.    while UNew > ''
  477.       UNext = NextWord(UNew);
  478.       P = pos(UNext + ' ',St)
  479.       if P > 0
  480.          delete(St,P,length(UNext) + 1)
  481.          delete(NewLine,P,length(UNext) + 1)
  482.       endif
  483.    endwhile
  484.    TrimTrail(NewLine)
  485.  
  486.    ;- delete double spaces
  487.  
  488.    while pos('  ',NewLine) > 0
  489.       Delete(NewLine,pos('  ',NewLine),1)
  490.    endwhile
  491.  
  492.    ;- delete space after =
  493.  
  494.    if pos('= ',NewLine) > 0
  495.       Delete(NewLine,pos('= ',NewLine)+1,1)
  496.    endif
  497.  
  498.    ChangeOrAddLine(NewLine,Line)
  499. EndProc
  500.  
  501.  
  502. Procedure TrailEqu (St)
  503.    if St contains '='
  504.       Return St
  505.    else
  506.       Return St + '='
  507.    endif
  508. EndProc
  509.  
  510.  
  511. Procedure OpenLog (RestOfLine)
  512. var LogFileName
  513.    LogFileName = RestOfLine
  514.    if LogFileName = ''
  515.       LogFileName = ForceExtension(IniFileName,'LOG')
  516.    endif
  517.    LogFileName = DefaultExtension(LogFileName,'LOG')
  518.    FileAssign(LogHandle,LogFileName)
  519.    LogFirstLine
  520.    Logging
  521. EndProc
  522.  
  523.  
  524. Procedure ChangeFile
  525. var St New Line Tmp FirstWord RestOfLine LogFileName X Y
  526.    Loop Changes
  527.       New = LoopVal
  528.       St = UChanges[LoopIndex]
  529.       if St > ''
  530.  
  531.          RestOfLine = St
  532.          FirstWord = NextWord(RestOfLine)
  533.  
  534.          if Hash(FirstWord)
  535.             St = RestOfLine
  536.             Tmp = NextWord(New)
  537.  
  538.             if CurrentSection = 0
  539.                if FirstWord = 'TESTMODE'
  540.                   TestMode
  541.  
  542.                elseif FirstWord = 'LOG'
  543.                   OpenLog(RestOfLine)
  544.                   FileCreate(LogHandle)
  545.  
  546.                elseif FirstWord = 'APPENDLOG'
  547.                   OpenLog(RestOfLine)
  548.                   FileAppend(LogHandle)
  549.  
  550.                elseif FirstWord = 'NOBACKUP'
  551.                   NoBackup = True
  552.  
  553.                elseif FirstWord = 'YAK'
  554.                   if not Quiet
  555.                      Writeln
  556.                      Yak = True
  557.                   endif
  558.  
  559.                elseif FirstWord = 'BACKUPNAME'
  560.                   BackupName = Uppercase(NextWord(RestOfLine))
  561.                   if BackupName StartsWith '*.'
  562.                      BackupExtension = BackupName
  563.                      delete(BackupExtension,1,2)
  564.                      BackupName = ''
  565.                   endif
  566.  
  567.                elseif FirstWord = 'DUPLICATES'
  568.                   if RightOfEqual(RestOfLine) = '[*]'
  569.                      AppendArray(GlobalDups,LeftOfEqual(RestOfLine))
  570.                   else
  571.                      Hash(RestOfLine) = True
  572.                   endif
  573.                   LoopVal = ''
  574.                   UChanges[LoopIndex] = ''
  575.  
  576.                endif
  577.             endif
  578.  
  579.             if FirstWord = 'DEL'
  580.                if RestOfLine StartsWith '['
  581.                   ApplySubst
  582.                   DelSection(RestOfLine)
  583.                else
  584.                   RestOfLine = TrailEqu(RestOfLine)
  585.                   DelLine(FindLine(RestOfLine))
  586.                endif
  587.  
  588.             elseif FirstWord = 'ADD'
  589.                Line = FindLine(St)
  590.                if Line = 0
  591.                   ChangeOrAddLine(New,0)
  592.                endif
  593.  
  594.             elseif FirstWord = 'CHANGE'
  595.                Line = FindLine(St)
  596.                if Line > 0
  597.                   ChangeOrAddLine(New,Line)
  598.                endif
  599.  
  600.             elseif FirstWord = 'ADDVALUE'
  601.                Line = FindLine(St)
  602.                if Line > 0
  603.                   X = Value(RightOfEqual(New)) + Value(RightOfEqual(Orig[Line]))
  604.                   Tmp = LeftOfEqual(New)
  605.                   ChangeOrAddLine(Tmp + Str(X),Line)
  606.                endif
  607.  
  608.             elseif FirstWord = 'ADDITEM'
  609.                Line = FindLine(St)
  610.                if Line > 0
  611.                   AddItem(Line,St)
  612.                else
  613.                   ChangeOrAddLine(New,0)
  614.                endif
  615.  
  616.             elseif FirstWord = 'DELITEM'
  617.                Line = FindLine(St)
  618.                if Line > 0
  619.                   DelItem(Line,St)
  620.                endif
  621.  
  622.             elseif FirstWord = 'SUBST'
  623.                if CurrentSection = 0
  624.                   AppendArray(SubFindG,CleanIniLine(NextWord(St)))
  625.                   AppendArray(SubReplaceG,NextWord(St))
  626.                else
  627.                   AppendArray(SubFind,CleanIniLine(NextWord(St)))
  628.                   AppendArray(SubReplace,NextWord(St))
  629.                endif
  630.  
  631.             elseif FirstWord = 'BEFORE'
  632.                St = TrailEqu(St)
  633.                InsertPos = FindLine(St)
  634.  
  635.             elseif FirstWord = 'AFTER'
  636.                St = TrailEqu(St)
  637.                X = FindLine(St)
  638.                if X > 0 then InsertPos = succ(X)
  639.  
  640.             elseif FirstWord = 'FIRST'
  641.                InsertPos = BlockStartIndex[CurrentSection]
  642.  
  643.             endif
  644.  
  645.          else
  646.  
  647.             ;- Process Sections
  648.  
  649.             if St StartsWith '['
  650.  
  651.                ;- New Group
  652.  
  653.                ApplySubst
  654.                FindSection(St)
  655.                if CurrentSection = 0
  656.                   AddSection(LoopVal)
  657.                endif
  658.  
  659.             else
  660.  
  661.                ;- Process Lines
  662.  
  663.                ChangeOrAddLine(New,Findline(St))
  664.  
  665.             endif
  666.  
  667.          endif
  668.       endif
  669.       IfLine = IfArray[LoopIndex]
  670.       if IfLine > ''
  671.          Interpret
  672.          if NumberOfElements Stack <> 0
  673.             Error ('Too Many Parameters!',LoopIndex)
  674.          endif
  675.       endif
  676.    EndLoop
  677.    ApplySubst
  678.    ApplySubstBlock(SubFindG,SubReplaceG,1,NumberOfElements(Orig))
  679. EndProc
  680.  
  681.  
  682. Procedure Help
  683. var Help HelpFile St
  684.    St = ForceExtension(FilePart(MenuFileName),'HLP')
  685.    HelpFile = ExistOnPath(St)
  686.    if HelpFile = ''
  687.       St = ForceExtension(FilePart(MenuFileName),'TXT')
  688.       HelpFile = ExistOnPath(St)
  689.    endif
  690.    Writeln
  691.    if HelpFile > ''
  692.       BoxHeader ' Viewing ' + HelpFile + ' '
  693.       DrawBox 1 1 ScreenWidth ScreenHeight
  694.       ViewTextFile(HelpFile)
  695.    endif
  696.    StandardIO
  697.    Writeln ProgName ' * Version 2.44 * Release Date: 11-17-94'
  698.    if IniToolMode
  699.       Writeln
  700.       Writeln 'Copyright 1994 by McAfee Inc. (408) 988-3832'
  701.       Writeln 'Copyright 1993-94 by Computer Tyme Inc. (417) 866-1222'
  702.       Writeln 'Licensed to McAfee Inc. from Computer Tyme Inc.'
  703.       Writeln 'All Rights Reserved'
  704.    else
  705.       Writeln 'Copyright 1993-94 by Marc Perkel * All Rights Reserved'
  706.       Include 'ADDRESS.INC'
  707.    endif
  708.    if HelpFile = ''
  709.       Writeln 'Missing file: ' St
  710.    endif
  711.    ExitMenu
  712. EndProc
  713.  
  714.  
  715. Procedure Beg
  716. var Jessica
  717.    BoxHeader ' * Shameless Beg Screen * '
  718.    DrawBox 10 8 61 7
  719.    Writeln
  720.    WriteCenter '* ' ProgName ' Evaluation Copy *'
  721.    Writeln
  722.    WriteCenter 'Please remember to register this software.'
  723.    Writeln
  724.    if Timer and 1 = 0
  725.       Jessica = Now - TimeOf('1-17-80') / SecondsInDay / 365 + 2
  726.       WriteCenter 'I have a ' Jessica ' year old daughter who wants to go shopping.'
  727.    else
  728.       WriteCenter "I'd sure hate to have to find a real job."
  729.    endif
  730.    Wait 600
  731.    EraseTopWindow
  732.    ClearKbdBuffer
  733. EndProc
  734.  
  735.  
  736. Procedure TestFreeMemory
  737.    if FreeMemory < 10000
  738.       Error('Not Enough Free Memory!',0)
  739.    endif
  740. EndProc
  741.  
  742.  
  743. Procedure Error (St,Line)
  744.    Writeln
  745.    if Line > 0
  746.       Writeln ProgName ' Error in line ' Line
  747.       Writeln St
  748.    else
  749.       Writeln ProgName ' Error: ' St
  750.    endif
  751.    ExitCode = 1
  752.    ExitMenu
  753. EndProc
  754.  
  755.  
  756. ;----- INITYME.INC has the conditional logic.
  757.  
  758. Include 'INITYME.INC'
  759.  
  760.  
  761. Procedure LookForCtlFile (Name)
  762. var St
  763.  
  764.    ;- IniTools Names
  765.  
  766.    Name = ForceExtension(Name,'CTL')
  767.    St = ExistOnPath(Name)
  768.    if St > '' then Return St
  769.  
  770.    St = CleanFileName(%CTLDIR% + '\' + Name)
  771.    if ExistFile (St) then Return St
  772.  
  773.    ;- IniMan Names
  774.  
  775.    Name = ForceExtension(Name,'DEF')
  776.    St = ExistOnPath(Name)
  777.    if St > '' then Return St
  778.  
  779.    St = CleanFileName(%S_CONFIG% + '\' + Name)
  780.    if ExistFile (St) then Return St
  781.  
  782.    Return ''
  783. EndProc
  784.  
  785.  
  786. Procedure Setup
  787. var St P
  788.  
  789.    TestFreeMemory
  790.    BlankTime = 0
  791.    BoxBorderColor Green Blue
  792.    BoxInsideColor White Blue
  793.    BoxHeaderColor Yellow Mag
  794.   ;Beg
  795.    Quiet = OptionSwitch(CmdLine,'Q')
  796.    BackupExtension = 'BNI'
  797.    FirstProcessFile = True
  798.    ChangeFileName = UpperCase(ParamStr(2))
  799.    IniFileName = UpperCase(ParamStr(3))
  800.  
  801.    IniToolMode = MenuFileName contains 'INITOOL'
  802.    if IniToolMode
  803.       ProgName = 'IniTool'
  804.    else
  805.       ProgName = 'IniTyme'
  806.    endif
  807.  
  808.    ExitCode = 0
  809.  
  810.    RestoreMode = ChangeFileName = 'RESTORE'
  811.  
  812.    if (IniFileName = '')
  813.       IniFileName = DefaultExtension(ChangeFileName,'INI')
  814.       ChangeFileName = LookForCtlFile(ChangeFileName)
  815.    else
  816.       if ChangeFileName > ''
  817.          if Extension ChangeFileName = ''
  818.             St = ForceExtension(ChangeFileName,'INI')
  819.             if ExistFile St
  820.                ChangeFileName = St
  821.             else
  822.                ChangeFileName = LookForCtlFile(ChangeFileName)
  823.             endif
  824.          endif
  825.       endif
  826.    endif
  827.  
  828.    if not RestoreMode
  829.       if (ChangeFileName = '') or not ExistFile(ChangeFileName)
  830.          Help
  831.       endif
  832.    endif
  833.  
  834.    StandardIO
  835.  
  836.    ;-- Duplicates List - Add your own duplicates here.
  837.  
  838.    HashLevel = 1
  839.    Hash('DEVICE=[386ENH]') = True
  840.  
  841.    if not Quiet then Writeln 'Processing Change File: ' ChangeFileName ' ...'
  842.  
  843.    ReadTextFile(ChangeFileName,Changes)
  844.  
  845.    Loop Changes
  846.       Trim(LoopVal)
  847.       LoopVal = EnvExpandString(LoopVal)
  848.    EndLoop
  849.  
  850.    UChanges = Changes
  851.    Loop UChanges
  852.       LoopVal = CleanIniLine(LoopVal)
  853.    EndLoop
  854.  
  855.    Loop UChanges
  856.       if LoopVal StartsWith 'IF '
  857.          IfArray[LoopIndex] = LoopVal
  858.          LoopVal = ''
  859.          Changes[LoopIndex] = ''
  860.          PushStack(LoopIndex)
  861.  
  862.       elseif LoopVal StartsWith '**'
  863.  
  864.          ;- IniMan Code
  865.  
  866.          delete(LoopVal,1,2)
  867.          St = LoopVal
  868.          St = NextWord(St)
  869.  
  870.          if St = 'BEGIN'
  871.  
  872.          elseif St = 'END'
  873.  
  874.          elseif St = 'ELSE'
  875.             IfArray[LoopIndex] = 'GOTO'
  876.             P = 0
  877.             Loop LoopIndex + 2 LoopLimit UChanges
  878.  
  879.                ;- Search forward for END
  880.  
  881.                if LoopVal = '**END'
  882.                   P = LoopIndex
  883.                   LoopIndex = LoopLimit
  884.                endif
  885.             EndLoop
  886.             if P > 0
  887.                GotoList[LoopIndex] = P
  888.             else
  889.                P = LoopLimit
  890.             endif
  891.  
  892.          else
  893.             LoopVal = 'IF ' + LoopVal
  894.             IfArray[LoopIndex] = LoopVal
  895.  
  896.             if UChanges[LoopIndex + 1] = '**BEGIN'
  897.                P = 0
  898.                Loop LoopIndex + 2 LoopLimit UChanges
  899.  
  900.                   ;- Search forward for END
  901.  
  902.                   if LoopVal = '**END'
  903.                      P = LoopIndex
  904.                      LoopIndex = LoopLimit
  905.  
  906.                   elseif LoopVal = '**ELSE'
  907.                      P = LoopIndex
  908.                      LoopIndex = LoopLimit
  909.  
  910.                   endif
  911.                EndLoop
  912.                if P > 0
  913.                   GotoList[LoopIndex] = P
  914.                else
  915.                   P = LoopLimit
  916.                endif
  917.  
  918.             elseif UChanges[LoopIndex + 1] StartsWith '['
  919.  
  920.                ;- Conditional applies to section
  921.  
  922.                Loop LoopIndex + 2 LoopLimit UChanges
  923.  
  924.                   ;- Search forward for next [Section]
  925.  
  926.                   if LoopVal StartsWith '['
  927.                      P = LoopIndex
  928.                      LoopIndex = LoopLimit
  929.                   endif
  930.                EndLoop
  931.                if P > 0
  932.                   GotoList[LoopIndex] = P - 1
  933.                else
  934.                   P = LoopLimit
  935.                endif
  936.  
  937.             else
  938.                GotoList[LoopIndex] = LoopIndex + 1
  939.             endif
  940.  
  941.          endif
  942.  
  943.          LoopVal = ''
  944.          Changes[LoopIndex] = ''
  945.  
  946.       elseif LoopVal = 'ENDIF'
  947.          LoopVal = ''
  948.          Changes[LoopIndex] = ''
  949.          GotoList[PopStack] = LoopIndex
  950.  
  951.       elseif LoopVal = 'ELSE'
  952.          LoopVal = ''
  953.          Changes[LoopIndex] = ''
  954.          IfArray[LoopIndex] = 'GOTO'
  955.          GotoList[PopStack] = LoopIndex
  956.          PushStack(LoopIndex)
  957.  
  958.       endif
  959.  
  960.    EndLoop
  961.  
  962.    ;-- if you forgot an Endif then the stack contains values.
  963.  
  964.    if NumberOfElements Stack <> 0
  965.       Error ('MisMatched Conditionals!',0)
  966.    endif
  967.  
  968.    Hash('ADD') = True
  969.    Hash('ADDITEM') = True
  970.    Hash('ADDVALUE') = True
  971.    Hash('AFTER') = True
  972.    Hash('APPENDLOG') = True
  973.    Hash('BACKUPNAME') = True
  974.    Hash('BEFORE') = True
  975.    Hash('CHANGE') = True
  976.    Hash('DEL') = True
  977.    Hash('DELITEM') = True
  978.    Hash('DUPLICATES') = True
  979.    Hash('FIRST') = True
  980.    Hash('LOG') = True
  981.    Hash('NOBACKUP') = True
  982.    Hash('SUBST') = True
  983.    Hash('TESTMODE') = True
  984.    Hash('YAK') = True
  985.  
  986.    SetupLibWords
  987.    TestFreeMemory
  988. EndProc
  989.  
  990.  
  991. Procedure ResetVariables
  992.    dispose(NameIndex)
  993.    dispose(BlockStartIndex)
  994.    dispose(BlockEndIndex)
  995.    dispose(SubFind)
  996.    dispose(SubReplace)
  997.    dispose(SubFindG)
  998.    dispose(SubReplaceG)
  999.    dispose(GlobalDups)
  1000. ;   HashDisposeLevel(2)
  1001.    LogGroup = ''
  1002.    CurrentSection = 0
  1003.    BackupName = ''
  1004.    BackupExtension = 'BNI'
  1005. EndProc
  1006.  
  1007.  
  1008. Procedure BackName
  1009.    if BackupName > '' then Return BackupName
  1010.    Return ForceExtension(IniFileName,BackupExtension)
  1011. EndProc
  1012.  
  1013.  
  1014. Procedure ProcessFile (Name)
  1015. var FileList MultiFile X
  1016.    if InputRedirected and FirstProcessFile
  1017.       IniFileName = ''
  1018.    else
  1019.       IniFileName = DefaultExtension(Name,'INI')
  1020.    endif
  1021.    FirstProcessFile = False
  1022.    ReadTextFile(IniFileName,Orig)
  1023.    TestFreeMemory
  1024.    if NumberOfElements Orig > 0
  1025.  
  1026.       ;- Loop Past Comments and blank lines
  1027.  
  1028.       X = 1
  1029.       while (X < NumberOfElements(Orig)) and ((Orig[X] StartsWith ';') or (Orig[X] = ''))
  1030.          X = X + 1
  1031.       endwhile
  1032.  
  1033.       if ExistFile(Orig[X])
  1034.          MultiFile = True
  1035.          FileList = Orig
  1036.          Loop FileList
  1037.             if LoopVal StartsWith ';' then LoopVal = ''
  1038.             if LoopVal > ''
  1039.                ProcessFile(LoopVal)
  1040.             endif
  1041.          EndLoop
  1042.       endif
  1043.    endif
  1044.    if not MultiFile
  1045.       if RestoreMode
  1046.          if ExistFile(BackName)
  1047.             Writeln 'Restoring ' IniFileName
  1048.             DelFile(IniFileName)
  1049.             FileRename(BackName,IniFileName)
  1050.          else
  1051.             Writeln BackName ' not Found!'
  1052.          endif
  1053.       else
  1054.          ResetVariables
  1055.          if not Quiet then Writeln 'Converting INI File: ' IniFileName ' '
  1056.          NeedsIndexing
  1057.          ChangeFile
  1058.          RemoveExtraBlankLines
  1059.  
  1060.          if TestMode
  1061.             WriteTextFile(BackName,Orig)
  1062.          else
  1063.             DelFile(BackName)
  1064.             FileRename(IniFileName,BackName)
  1065.             WriteTextFile(IniFileName,Orig)
  1066.          endif
  1067.  
  1068.          if NoBackup
  1069.             DelFile(BackName)
  1070.          endif
  1071.  
  1072.          if Logging
  1073.             FileClose(LogHandle)
  1074.             Logging Off
  1075.          endif
  1076.  
  1077.          if Yak then Writeln
  1078.       endif
  1079.    endif
  1080. ;  Writeln(FreeMemory)
  1081. EndProc
  1082.  
  1083.  
  1084. Procedure Main
  1085.    Setup
  1086.    ProcessFile(IniFileName)
  1087. EndProc
  1088.